//
//  CreditViewController.m
//  U_card
//
//  Created by 陈如意 on 2018/3/22.
//  Copyright © 2018年 陈如意. All rights reserved.
//

#import "CreditViewController.h"
#import "YLProgressBar.h"
//#import "VHLNavigation.h"

#define JCredit @"http://pay.mishua.cn/cc.html"
@interface CreditViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView * webView;
@property (strong, nonatomic) YLProgressBar *newsProgressView;

@end

@implementation CreditViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"办信用卡";
    
    self.webView = [UIWebView new];
    
    self.webView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight-KNAVIGATIONBARHEIGHT);
    
    [self.view addSubview:self.webView];
    
    self.webView.scalesPageToFit = YES;
    self.webView.delegate = self;
    
    NSURL *url = [NSURL URLWithString:JCredit];//创建URL
    NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建
    [self.webView loadRequest:request];//加载
    
//    CGFloat navHeight = [self vhl_navgationBarHeight];

    _newsProgressView = [[YLProgressBar alloc]initWithFrame:CGRectMake(0,KNAVIGATIONBARHEIGHT-KSTATUBARHEIGHT-2, KScreenWidth, 2)];
    NSArray *tintColors = @[[UIColor colorWithHexString:@"fdeded"],[UIColor colorWithHexString:@"#f85154"]];
    _newsProgressView.progressTintColors = tintColors;
    _newsProgressView.type   = YLProgressBarTypeFlat;
    _newsProgressView.hideStripes        = YES;
    _newsProgressView.hideTrack          = YES;
    _newsProgressView.behavior           = YLProgressBarBehaviorDefault;
    [self.navigationController.navigationBar addSubview: _newsProgressView];
    

}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_newsProgressView setProgress:1 animated:YES];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1  * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        
        _newsProgressView.backgroundColor = [UIColor clearColor];
        [_newsProgressView removeFromSuperview];
        
    });
 
    NSLog(@"成功");
    
}
//加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"%@",error.localizedDescription);
    [_newsProgressView setProgress:1 animated:YES];
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1  * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        
        _newsProgressView.backgroundColor = [UIColor clearColor];
        [_newsProgressView removeFromSuperview];
        
    });
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
